package cn.bsuc.infirmary.web.controller;

import cn.bsuc.infirmary.domain.Systemdictionary;
import cn.bsuc.infirmary.query.QueryObject;
import cn.bsuc.infirmary.service.ISystemdictionaryService;
import cn.bsuc.infirmary.util.JSONResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/systemDictionary")
public class SystemDictionaryController {
    @Autowired
    private ISystemdictionaryService systemdictionaryService;

    @RequiresPermissions(value = {"字典页面", "systemdictionary:list"}, logical = Logical.OR)
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model) {
        model.addAttribute("pageInfo", systemdictionaryService.selectQueryObject(qo));
        return "systemdictionary/list";
    }


    @RequiresPermissions(value = {"字典删除", "systemdictionary:delete"}, logical = Logical.OR)
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(Long id) {
        if (id != null) {
            systemdictionaryService.delete(id);
        }
        return new JSONResult();
    }

    @RequiresPermissions(value = {"字典增新", "systemdictionary:saveOrUpdate"}, logical = Logical.OR)
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Systemdictionary entity) {
        systemdictionaryService.saveOrUpdate(entity);
        return new JSONResult();
    }
}
